﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Class1
    {
        private static string constr = "server=.;database=chou;uid=sa;pwd=123456a";
        private static string sql = "select * from Userinfo";

        public static void Normalconnection()
        {

            string constr = "server=.;database=chou;uid=sa;pwd=123456a";
            SqlConnection conn = new SqlConnection(constr);
            string sql = "select * from Userinfo";
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            var read = cmd.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "学号", "姓名", "性别", "籍贯");

            while (read.Read())
            {
                Console.WriteLine("{0}\t{1}{2}\t{3}", read["StuID"], read["StuName"], read["StuSex"], read["StyAdd"]);
            }
            conn.Close();


        }


        public static void outdate()
        {


            SqlDataAdapter sqldataAdapter = new SqlDataAdapter(sql, constr);


            DataTable dataTable = new DataTable();

            sqldataAdapter.Fill(dataTable);



            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "学号", "姓名", "性别", "籍贯");




            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}{2}\t{3}", dataTable.Rows[i]["StuID"], dataTable.Rows[i]["StuName"], dataTable.Rows[i]["StuSex"], dataTable.Rows[i]["StyAdd"]);
            }

        }
}   }
